package com.ys.zero.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ys.zero.bean.Collection;
import com.ys.zero.bean.User;
import com.ys.zero.dao.UserDao;

/**
 * 用户收藏文章，影视展示severlet
 * @author 满熊
 *
 */
@WebServlet("/collection/*")
public class CollectionServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private UserDao udao = new UserDao();

	//用户文章收藏展示
	public void showarticle(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user = (User) request.getSession().getAttribute("loginedUser");//获取当前会话对象
		List<Collection> colleciton = udao.showArticle(user.getAccount());
		toJson(response, colleciton);
	}

	
	
	public void showVideo(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException{
		User user = (User) request.getSession().getAttribute("loginedUser");//获取当前会话对象
		List<Collection> videoCollection = udao.showVideo(user.getAccount());
	}

	/**
	 * 插入收藏数据
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void insertCollection(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String uaid  = request.getParameter("uaid");
		String link  = request.getParameter("link");
		User user = (User) request.getSession().getAttribute("loginedUser");//获取当前会话对象
		udao.insertCollection(user.getAccount(),uaid,link);
	}
	
	/**
	 * 删除指定收藏数据
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void delCollection(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String link  = request.getParameter("link");
		User user = (User) request.getSession().getAttribute("loginedUser");//获取当前会话对象
		udao.delCollection(user.getAccount(),link);
	}
	

}
